Use titlebar action settings for CSD windows
authorMatthias Clasen <mclasen@redhat.com>
Thu, 25 Sep 2014 05:26:06 +0000 (01:26 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 25 Sep 2014 18:54:49 +0000 (14:54 -0400)
Instead of hardcoding these actions, consult the settings.
Note that not all of the actions supported by gnome-shell are
implemented here, only maximize, minimize, lower, and menu.

https://bugzilla.gnome.org/show_bug.cgi?id=729782

gtk/gtkwindow.c

index e6dbb128151e907b88f8f4198b30c9f30f6df3a1..8099f3a059f557cf4649b20bdf492d5c86882f36 100644 (file)
@@ -1360,24 +1360,47 @@ gtk_window_titlebar_action (GtkWindow      *window,
                             guint           button,
                             gint            n_press)
 {
+  GtkSettings *settings;
+  gchar *action = NULL;
+  gboolean retval = TRUE;
+
+  settings = gtk_widget_get_settings (GTK_WIDGET (window));
   switch (button)
     {
     case GDK_BUTTON_PRIMARY:
       if (n_press == 2)
-        {
-          _gtk_window_toggle_maximized (window);
-          return TRUE;
-        }
-      return FALSE;
+        g_object_get (settings, "gtk-titlebar-double-click", &action, NULL);
+      break;
     case GDK_BUTTON_MIDDLE:
-      gdk_window_lower (gtk_widget_get_window (GTK_WIDGET (window)));
-      return TRUE;
+      g_object_get (settings, "gtk-titlebar-middle-click", &action, NULL);
+      break;
     case GDK_BUTTON_SECONDARY:
-      gtk_window_do_popup (window, (GdkEventButton*) event);
-      return TRUE;
-    default:
-      return FALSE;
+      g_object_get (settings, "gtk-titlebar-right-click", &action, NULL);
+      break;
     }
+
+  if (action == NULL)
+    retval = FALSE;
+  else if (g_str_equal (action, "none"))
+    retval = FALSE;
+    /* treat all maximization variants the same */
+  else if (g_str_has_prefix (action, "toggle-maximize"))
+    _gtk_window_toggle_maximized (window);
+  else if (g_str_equal (action, "lower"))
+    gdk_window_lower (gtk_widget_get_window (GTK_WIDGET (window)));
+  else if (g_str_equal (action, "minimize"))
+    gdk_window_iconify (gtk_widget_get_window (GTK_WIDGET (window)));
+  else if (g_str_equal (action, "menu"))
+    gtk_window_do_popup (window, (GdkEventButton*) event);
+  else
+    {
+      g_warning ("Unsupported titlebar action %s\n", action);
+      retval = FALSE;
+    }
+
+  g_free (action);
+
+  return retval;
 }
 
 static void